# -*- coding: gbk -*-

import web, cjson
import hall, uigate

class UICommit:
    GET = web.autodelegate('GET_')

    def GET_setThreadAsRead (self, threadID):
        threadID = int(threadID[1:])
        thread = uigate.ThreadView(threadID)

        web.header('Content-Type', 'text/javascript')        
        print cjson.encode(thread.setAsRead())

    def GET_setTagAsRead (self, tagName):
        tagName = tagName[1:]
        tag = uigate.TagView(tagName)

        web.header('Content-Type', 'text/javascript')
        print cjson.encode(tag.setAsRead())

    def GET_setStar (self, threadID):
        threadID = int(threadID[1:])
        thread = uigate.ThreadView(threadID, False)

        web.header('Content-Type', 'text/javascript')        
        print cjson.encode(thread.setStar())

    def GET_clearStar (self, threadID):
        threadID = int(threadID[1:])
        thread = uigate.ThreadView(threadID, False)

        web.header('Content-Type', 'text/javascript')        
        print cjson.encode(thread.clearStar())

    def GET_modifyTag (self, path):
        docID, data = path[1:].split('/', 1);
        docID = int(docID)
        tagList = data.split()

        mesg = uigate.MessageView(docID)        
        print cjson.encode(mesg.modifyTag(tagList))
        

